package com.customization.unionpay.market.workflowaction;

import com.customization.unionpay.market.maketEnum.InstructionEnum;
import com.customization.unionpay.market.util.FormDataUtils;
import weaver.generalledger.action.ZzgdExecuteInstrucitonAction;
import weaver.integration.logging.Logger;
import weaver.integration.logging.LoggerFactory;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.Map;

/**
 * @author sjm
 * @description 营销个税计提单预算归档相关
 * @create 2024-08-07 9:45
 */
public class MarketingPersonalTaxLadingEndAction implements Action {

    private static final Logger log = LoggerFactory.getLogger(MarketingPersonalTaxLadingAction.class);

    @Override
    public String execute(RequestInfo requestInfo) {

        try {

            Map<String, Object> allFormData = com.customization.unionpay.market.util.FormDataUtils.getAllFormData(requestInfo);

            Map<String, String> mainMap = (Map<String, String>) allFormData.get("mainMap");

            // 主 业务日期        ywrq
            String ywrq = mainMap.get("ywrq");
            log.info("ywrq："+ywrq);
            // 主 预算控制期      yskzq
            String yskzq = mainMap.get("yskzq");
            log.info("yskzq："+yskzq);
            String ywrqStr = com.customization.unionpay.market.util.FormDataUtils.changeDateString("yyyy-MM-dd", ywrq, "yyyy");
            String yskzqStr = FormDataUtils.changeDateString("yyyy-MM-dd", yskzq, "yyyy");

            String instruction = "";
            if (ywrqStr.equals(yskzqStr)) {
                instruction = com.customization.unionpay.market.maketEnum.InstructionEnum.SFZYQZX.toString();
            } else {
                instruction = InstructionEnum.XMSFZYQZX.toString();
            }
            log.info("instruction："+instruction);
            ZzgdExecuteInstrucitonAction zzgdExecuteInstrucitonAction = new ZzgdExecuteInstrucitonAction();
            zzgdExecuteInstrucitonAction.setZl(instruction);
            String execute = zzgdExecuteInstrucitonAction.execute(requestInfo);
            if("0".equals(execute)){
                String messageid = requestInfo.getRequestManager().getMessageid();
                log.info("messageid："+messageid);
                String messagecontent = requestInfo.getRequestManager().getMessagecontent();
                log.info("messagecontent："+messagecontent);
                return Action.FAILURE_AND_CONTINUE;
            }else {
                log.info("预算调用成功！");
            }
        } catch (Exception e) {
            // 异常报错是填写异常信息，阻止流程继续流转
            requestInfo.getRequestManager().setMessageid("10001");
            requestInfo.getRequestManager().setMessagecontent(e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
        return Action.SUCCESS;
    }
}
